/**
 * @file    Expression classname is undefined on line 2, column 15 in Templates/Classes/Class.java.
 * @author  Haseeb Yousaf
 * @see     LICENSE (MIT style license file)
 * @version 1.0
 * @date    Nov 22, 2011 5:57:06 PM
 */
package carrello.model.entitydao;
import java.util.Set;
import java.util.List;
import carrello.model.entities.*;
import static carrello.util.EntityManagerUtil.getEntityManager;

public class ProductDAO {
    public void create(Product c)
    {
        getEntityManager().beginUnitOfWork();
        getEntityManager().store(c);
        getEntityManager().endUnitOfWork();
    }
    
    public void createAll(Set<Product> c)
    {
        getEntityManager().beginUnitOfWork();
        getEntityManager().storeAll(c);
        getEntityManager().endUnitOfWork();
    }
    
    public Product getById(int id)
    {
        return Product.getProductById(id);
    }
    
    public List<Product> getByName(String name)
    {
        return Product.getProductByName(name);
    }
    public List getProductInfoById(int id)
    {
        return Product.getAllProductInfoById(id);
    }
    
    public List<Product> getAll()
    {
        return Product.getAllProducts();
    }
    
    public void delete(Product c)
    {
        getEntityManager().beginUnitOfWork();
        getEntityManager().remove(c);
        getEntityManager().endUnitOfWork();
    }
    
       public void deleteAll(Set<Product> c)
    {
        getEntityManager().beginUnitOfWork();
        getEntityManager().removeAll(c);
        getEntityManager().endUnitOfWork();
    }
}
